import random
import numpy as np


# 生成城市坐标
def generate_cities(num_cities, seed=None):
    if seed is not None:
        random.seed(seed)
        np.random.seed(seed)

    cities = []
    for _ in range(num_cities):
        x = random.uniform(0, 100)
        y = random.uniform(0, 100)
        cities.append((x, y))

    return np.array(cities)


# 初始化种群
def initialize_population(pop_size, cities):
    population = []
    base = list(range(len(cities)))

    for _ in range(pop_size):
        individual = base.copy()
        random.shuffle(individual)
        population.append(individual)

    return population
